package net.sdd.school.common.exception;

import net.sdd.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @RestControllerAdvice = @ControllerAdvice + @ResponseBody
 * 1、此注解标识当前类为全局异常类
 * 2、根据指定的异常类型返回对应的错误
 */
@RestControllerAdvice
public class GlobalException {

    // @ExceptionHandler 指定处理的异常类型
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e){
        e.printStackTrace();
        return Result.fail().message(e.getMessage());
    }
}
